package com.lgj.feign;

import com.lgj.utils.IpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author guangjie.liao
 * @Date: 2022/10/27 18:23
 * @Description:
 */
@Slf4j
@RestController
public class NacosController {
    /**
     * 开发
     */
    private static final String DEV = "192.168.31.0/100";
    private static final String DEV_SERVER = "192.168.31.234";
    /**
     * 测试
     */
    private static final String TEST = "43.138.243.0/91";
    private static final String TEST_SERVER = "43.138.243.91";
    /**
     * 生产
     */
    private static final String PRO = "192.168.12.0/100";
    private static final String PRO_SERVER ="43.138.243.91";

    @GetMapping("/nacos/serverlist")
    public String nacosServerAddress(HttpServletRequest request){
        String ip  = IpUtil.getIpAddr(request);
        String serverList = null;
        if (IpUtil.ipIsInNet(ip,DEV)){
            serverList = DEV_SERVER;
        }
        if (IpUtil.ipIsInNet(ip,TEST)){
            serverList =  TEST_SERVER;
        }
        log.info("{}获取nacos服务列表：{}",ip,serverList);
        return serverList;
    }
}
